<html>
<head>

<title>Groovy Goodness: Clear Time Portion of a Date</title>

<script language="javascript" src="scripts/shCore.js"></script> 
<script language="javascript" src="scripts/shLegacy.js"></script> 
<script language="javascript" src="scripts/shBrushJava.js"></script> 
<script language="javascript" src="scripts/shBrushXml.js"></script> 
<script language="javascript" src="scripts/shBrushJScript.js"></script> 
<script language="javascript" src="scripts/shBrushGroovy.js"></script> 
<script language="javascript" src="scripts/shBrushPlain.js"></script> 
<script language="javascript" src="scripts/shBrushBash.js"></script> 
 
<link href="styles/reset.css" rel="stylesheet" type="text/css" />
<link href="styles/shCore.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="styles/shThemeRDark.css"/>
<link href="styles/blog.css" rel="stylesheet" type="text/css" />

</head>
<body>

<a href="index.html">Back to index</a>

<h3 class="post-title">Groovy Goodness: Clear Time Portion of a Date</h3>

<div class="post">
<p>Working with dates in Groovy is easy. We get a lot of extra functionality compared to the standard Java Date class. One of the extra methods added to the Date class since Groovy 1.6.8 is <code>clearTime()</code>. With <code>clearTime()</code> we reset the time portion of a date to 12 o'clock midnight. This makes it easier to compare dates if we only are interested in the date, month, year parts.</p>
<pre class="brush:groovy">
// Create new date.
def d = new Date(year: 2010, month: Calendar.JULY, date: 1, 
                                hours: 7, minutes: 12, seconds: 0)

assert '7/1/10 7:12:00 AM' == d.dateTimeString

// Reset time portion of the date.
d.clearTime()

assert '7/1/10 12:00:00 AM' == d.dateTimeString
</pre
</div>

<script language="javascript"> 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
SyntaxHighlighter.defaults['first-line'] = 0;
SyntaxHighlighter.defaults['auto-links'] = false;
SyntaxHighlighter.all();
dp.SyntaxHighlighter.HighlightAll('code');
</script>

</body>
</html>